{% include 'head.html' %}








<body>





  <!-- 最为层容器 -->
  <div class="jd_container" style="background-color: #f0f0f0;">
    <!-- 顶部 -->
    <div class="jd_header" style="height: 50px;background: #dce2ec;width: 100%">

      <!--<span style="float: left;margin-left: -18%;margin-top: 15px;">货比三家</span>-->
      <a onclick="window.history.back();" >
        <div style="width: 10%;margin-left: -20%;">
        <span style="float: left;margin-top: 12px;font-size: 23px;color: #000;">
          <i class="fa fa-chevron-left">
          </i>
        </span>
        </div>
      </a>
      
      <div style="text-align:center;margin-top: 5%;float: left;width: 90%;">
        <span style="font-size: 19px;"><b>修改头像</b></span>
      </div>

      <a onclick="window.history.back();" >
        <div style="margin-right: -15%;float: right;margin-top: 12px;">
        <span style="font-size: 23px;color: #000;top:0;">
          <i class="fa fa-search">
          </i>
        </span>
      </div>
      </a>

    </div>


    <div style="width: 100%;height: 100px;background-color: #fff;"></div>



    <div style="text-align: center;background-color: #fff;">
        <form id="formdatas">
            <div class="form-group" id="uploadForm" enctype='multipart/form-data'>
                <div class="fileinput fileinput-new" data-provides="fileinput"  id="exampleInputUpload">
                    <div class="fileinput-new thumbnail" style="width: 200px;height: auto;max-height:150px;">
                        <img id='picImg' style="width: 100%;height: auto;max-height: 140px;" src="{{ headimg }}" alt="" />
                    </div>
                    <div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 200px; max-height: 150px;"></div>
                    <div>
                        <span class="btn btn-primary btn-file" style="width: 100%;">
                            <span class="fileinput-new" >点击此处选择更换头像</span>
                            <span class="fileinput-exists">换一张</span>
                            <!--<input type="file" id="picID" accept="image/*" mutiple="mutiple" capture="camera" />-->
                            <input type="file" id="picID" accept="image/*" mutiple="mutiple" capture="camera" />
                        </span>
                        <a href="javascript:;" class="btn btn-warning fileinput-exists" data-dismiss="fileinput" style="width: 100%;">移除</a>
                    </div>
                </div>
            </div>


        </form>

        <div style="width: 100%;height: 100px;background-color: #fff;"></div>

         <a href="/my" style="color: #000;"><h3 style="margin-left: 8%;margin-top: 20%;float: left;">返回</h3></a>
  <a style="color: #000;" onclick="changeuserhead();" ><h3 style="margin-right: 8%;margin-top: 20%;float: right;">提交修改</h3></a>

    </div>

<script type="text/javascript">

    function changeuserhead(){

      var formdata = new FormData();


      var headimg = $('#picID').get(0).files[0];
      //alert(headimg);
      console.log(headimg);
      
      formdata.append('headimg',headimg);

      console.log(formdata);

      if(headimg != undefined){
        //post_api_ajax3(formdata,"setuserinfoapi",setnamego_show);
        $.ajax({
            url: api_path+"/changehead",
            type: 'post',
            cache: false,
            processData:false,
            contentType:false,
            data: formdata,
            dataType:'JSON',
            success:function (datas) {
                //alert(datas);
                if(datas == 0){

                    webToast("上传的头像格式错误！","middle",3000);
                }
                else if(datas == 1){
                  webToast("设置成功","middle",2000);
                  window.location.href="/my";
                }
                else if(datas == 2){

                webToast("异常请求，开发不易请勿破坏","middle",2000);
                window.location.href="/";
                }

            }
        });
      }
      else{
        alert("请添加头像");
      }
    }

</script>



</body>


{% include 'js.html' %}

</html>